<template>
  <div>
    <!-- 查询 -->
    <tl-list-search ref="search" :query-param="queryParam" @search="doQuery" :isDisplayDefaultSearch="false" :isDisplaySearch="false" v-if="isHeaderDisplay">
      <template slot="search">
        <el-form-item label="部门">
          <tl-ref-dept v-model="queryParam.qry_deptcode" style="width:300px" :initDisplayData.sync="queryParam.qry_deptname" dataType="code" :singleSelect="true" :externalQueryParam="{qry_enabled:1}" @change="changedept"></tl-ref-dept>
        </el-form-item>
        <!-- <el-form-item label="项目">
          <el-input v-model="queryParam.qry_dispprojectid" :disabled="true" class="tl-ref-selector" style="width:300px">
            <el-button slot="append" type="primary" icon="el-icon-search" @click="openpmProjectRefDialog"></el-button>
          </el-input>
        </el-form-item> -->
        <el-form-item label="日期" prop="qry_begindocdate">
          <el-date-picker v-model="queryParam.qry_begindocdate" type="date" style="width:140px" value-format="yyyy-MM-dd" placeholder="开始日期" @change="changebegindocdate" />至
          <el-date-picker v-model="queryParam.qry_enddocdate" type="date" style="width:140px" value-format="yyyy-MM-dd" placeholder="结束日期" @change="changeenddocdate" />
        </el-form-item>
        <el-button class="filter-item" type="primary" icon="el-icon-search" @click="doQuery">搜索</el-button>
        <el-button class="filter-item" type="primary" icon="el-icon-refresh-right" @click="resetQueryParam" :disabled="isreset">重置</el-button>
        <el-button class="filter-item" type="primary" icon="el-icon-download" @click="doExportExcel">导出</el-button>
      </template>
    </tl-list-search>
    <div>
      <!--表格渲染-->
      <el-table class="tl-table" ref="mainTable" :height="tableHeight" resizable-key="tableHeight" :resizable-refs="tableResizeRefs" v-loading="loading" :data="datas" @selection-change="doSelectChange" @sort-change="doSortChange" row-key="id" border fit :row-class-name="doChangeRowClassName">
        <el-table-column type="index" label="序号" width="55px" align="center"></el-table-column>
        <el-table-column prop="deptname" label="部门名称" min-width="400px" sortable="custom" sort-by="deptname" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="deptcode" label="部门编号" width="200px" sortable="custom" sort-by="deptcode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="num" label="实际天数" width="100px" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
      </el-table>
      <!-- 列表分页 -->
      <el-row class="pagebar" ref="pager">
        <el-pagination @size-change="doChangeSize" @current-change="doChangeIndex" :current-page="pageInfo.currentPage" :page-sizes="pageInfo.pageSizes" :total="pageInfo.totalCount" layout="total, sizes, prev, pager, next, jumper" background class="tl-table-pagination"> </el-pagination>
      </el-row>
      <tlpm-project-ref ref="pmProjectRef" @confirm="getpmProjectRefData" :isSingleSelect="true"></tlpm-project-ref>
    </div>
  </div>
</template>

<script>
/** mixins */
import { mixin_list } from '@tapui/mixins/mixin_list'
import { mixin_base } from '@tapui/mixins/mixin_base'
/** 子组件 */
import tlpmProjectRef from '@/views/ProjectManage/pmProject/refList.vue'
import tlpmTeamRef from '@/views/ProjectManage/pmTeam/refList.vue'
import { validateNull } from '@tapui/utils/validate'
/** 工具类 */
import { getAction, putAction, postAction, deleteAction } from '@tapui/utils/http'
export default {
  name: 'taskLogDept',
  mixins: [mixin_list, mixin_base],
  components: { tlpmProjectRef, tlpmTeamRef },
  data() {
    return {
      description: '部门工作汇总',
      urlPrefix: '/pm/taskLog/',
      url: {
        queryCodeList: '/pm/taskLog/dataCodeList',
        exportExcel: '/pm/taskLog/exportTaskLogDeptExcel',
        deptList: '/pm/taskLog/deptStatistics'
      },
      // 排序参数
      sorterInfo: {
        sidx: 'deptcode',
        sord: 'asc'
      },
      isQueryOnCreated: false,
      isreset: false
    }
  },
  methods: {
    changedept() {
      if (JSON.stringify(this.queryParam) !== '{}' && this.queryParam.qry_deptcode !== '') {
        this.isreset = false
      } else {
        this.isreset = true
      }
    },
    changebegindocdate() {
      if (JSON.stringify(this.queryParam) !== '{}' && this.queryParam.qry_begindocdate !== '') {
        this.isreset = false
      } else {
        this.isreset = true
      }
    },
    changeenddocdate() {
      if (JSON.stringify(this.queryParam) !== '{}' && this.queryParam.qry_enddocdate !== '') {
        this.isreset = false
      } else {
        this.isreset = true
      }
    },
    afterLoadData() {
      this.isreset = false
      if ((typeof this.queryParam.qry_begindocdate === 'undefined' &&
        typeof this.queryParam.qry_enddocdate === 'undefined' && this.queryParam.qry_deptcode === '') || (typeof this.queryParam.qry_begindocdate === 'undefined' &&
          typeof this.queryParam.qry_enddocdate === 'undefined' && typeof this.queryParam.qry_deptcode === 'undefined')) {
        this.isreset = true
      }
    },
    assignDefaultValue() {
      // this.$set(this.queryParam, 'qry_deptcode', this.dept.code)
      // this.$set(this.queryParam, 'qry_deptname', this.dept.name)
    },
    // 禁用表格前面的选择
    doDisableCheckBox(row, index) {
      if (row.state !== 0 && row.state !== 2) {
        return false
      } else {
        return true
      }
    },
    resetQueryParam() {
      this.queryParam = {}
      this.loadData({ currentPage: 1 })
      this.changebegindocdate()
      this.changeenddocdate()
      this.changedept()
    },
    /** 打开项目参照 */
    openpmProjectRefDialog() {
      this.$refs.pmProjectRef.visible = true
    },
    /** 获取项目参数数据 */
    getpmProjectRefData(selectionRow, selectKey, selectionValue) {
      const { id, name } = selectionRow
      this.$set(this.queryParam, 'qry_projectid', id)
      this.$set(this.queryParam, 'qry_dispprojectid', name)
    },
    /** 列表数据加载开始 */
    loadData(paramMap) {
      if (!this.url.deptList) {
        this.$tap.alert('请设置deptList地址!', 'warning')
        return
      }
      // 得到加载分页
      if (validateNull(paramMap) === false && Object.keys(paramMap).indexOf('currentPage') > -1) {
        this.pageInfo.currentPage = paramMap['currentPage']
      }
      if (!this.beforeLoadData()) return
      // 查询条件
      var params = this.getQueryParams()
      // 数据查询
      this.loading = true
      getAction(this.url.deptList, params)
        .then((res) => {
          if (res.success) {
            this.datas = res.result.dataList
            this.pageInfo.totalCount = res.result.totalCount
          } else {
            this.$tap.alert(res.message, 'warning')
          }
          this.afterLoadData()
          this.loading = false
        })
        .catch((err) => {
          this.loading = false
        })
    }
  },
  mounted() {
    this.assignDefaultValue()
  }
}
</script>

<style scoped></style>
